package top.jandmla.shop.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.jandmla.shop.bean.Discount;
import top.jandmla.shop.bean.Product;
import top.jandmla.shop.bean.pojo.QueryDto;
import top.jandmla.shop.dao.ProductMapper;
import top.jandmla.shop.service.ProductService;
import top.jandmla.shop.utils.result.BaseResult;

import javax.annotation.Resource;

/**
 * <p>
 *
 * </p>
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {

    @Resource
    private ProductMapper mapper;

    @Override
    public BaseResult<IPage<Product>> selectPage(QueryDto<Product> dto) {
        QueryWrapper<Product> qw = new QueryWrapper<>();
        if (dto != null){
            Product product = dto.getQuery();
            if (product != null){
                if (product.getId() > 0)
                    qw.eq("id",product.getId());
                if (StringUtils.isNotBlank(product.getProductName()))
                    qw.like("productName",product.getProductName());
                if (product.getProductType() > 0)
                    qw.eq("productType",product.getProductType());

//                    qw.like("discountIntro",product.getDiscountintro());
//                if (product.getDiscount() > 0.0)
//                    qw.eq("discount",product.getDiscount());
            }
            return BaseResult.success(mapper.selectPage(dto.getPage(),qw));
        }
        return BaseResult.fail(5000,"请求参数错误！");
    }
}
